package com.unlcn.ils.crsc.service.security.domains;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * Created by qichao on 2017/11/29.
 */
public class JwtUser implements UserDetails {
    private final String accountCode;
    private final String pwd;
    private final String userCode;
    private final String userName;
    private final String mobile;
    private final String email;
    private final Integer accountId;
    private final Integer entityId;
    private final Integer userId;
    private final Collection<? extends GrantedAuthority> authorities;

    public JwtUser(int accountId, String accountCode,
                   String userCodeode, String userName, String pwd, String mobile, String email, Integer entityId, Integer userId, Collection<? extends GrantedAuthority> authorities) {
        this.userName = userName;
        this.userCode = userCodeode;
        this.accountCode = accountCode;
        this.accountId=accountId;
        this.pwd=pwd;
        this.mobile=mobile;
        this.email = email;
        this.entityId = entityId;
        this.userId = userId;
        this.authorities = authorities;
    }

    //返回用户的角色列表
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    // 密码
    @Override
    public String getPassword() {
        return this.pwd;
    }

    // 用户名
    @Override
    public String getUsername() {
        return this.userName;
    }

    // 账户是否未过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    // 账户是否未锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    // 账户是否激活
    @Override
    public boolean isEnabled() {
        return true;
    }

    // 密码是否未过期
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    public String getPwd() {
        return pwd;
    }

    public String getUserCode() {
        return userCode;
    }

    public String getUserName() {
        return userName;
    }

    public String getMobile() {
        return mobile;
    }

    public String getEmail() {
        return email;
    }

    public Integer getAccountId() {
        return accountId;
    }

    public String getAccountCode() {
        return accountCode;
    }

    public Integer getEntityId() {
        return entityId;
    }

    public Integer getUserId() {
        return userId;
    }

    @Override
    public String toString() {
        return "JwtUser{" +
                "accountCode='" + accountCode + '\'' +
                ", pwd='" + pwd + '\'' +
                ", userCode='" + userCode + '\'' +
                ", userName='" + userName + '\'' +
                ", mobile='" + mobile + '\'' +
                ", email='" + email + '\'' +
                ", accountId=" + accountId +
                ", entityId=" + entityId +
                ", userId=" + userId +
                ", authorities=" + authorities +
                '}';
    }
}
